package com.hzhc.controller.declare;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.entity.CntrInfo;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.DeclareCarService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.DeclareCarVo;
import com.hzhc.vo.YwOrderCntrVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 卡口记录 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-05-30
 */
@RestController
@RequestMapping("/declareCar")
@RequiredArgsConstructor
public class DeclareCarController extends BaseController {
    private final DeclareCarService declareCarService;

    /**
     * 卡口进卡页面列表
     */
    @RequestMapping("/getDeclareCarList")
    @ResponseBody
    public ResultUtil<List<DeclareCarVo>> getDeclareCarList(@RequestBody DeclareCarVo vo) {
        Page<DeclareCarVo> pagination = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<DeclareCarVo> cntrSizes = declareCarService.getDeclareCarList(vo, pagination);
        return ResultUtil.build(cntrSizes, pagination.getTotal(),pagination.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    //进场车辆列表--提重回空理货--箱号下拉框数据
    @RequestMapping("/getTzhkCntrList")
    public ResultUtil<List<YwOrderCntrVo>> getTzhkCntrList(HttpServletRequest request, @RequestBody DeclareCarVo vo){
        List<YwOrderCntrVo> list = declareCarService.getTzhkCntrList(vo);
        return  ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
    }

    @PostMapping("/updateRet")
    @ResponseBody
    @SysTemLog(operModul = "卡口管理-卡口进卡编辑", operType = "编辑", operDesc = "卡口进卡编辑功能", modular = "PC")
    public ResultUtil<T> updateRet(HttpServletRequest request,@RequestBody DeclareCarVo vo) {
        UserDto user = TokenUtil.getUser(request);
        vo.setUserName(user.getRealname());
        vo.setUserId(user.getId());
        return declareCarService.updateDeclareCar(vo);
    }

    @RequestMapping("/delete/{id}")
    @SysTemLog(operModul = "卡口管理-卡口进卡删除", operType = "删除", operDesc = "卡口进卡删除功能", modular = "PC")
    public ResultUtil<T> deleteRet(@PathVariable int id) {
        return declareCarService.deleteDeclareCar(id);
    }

    /**
     * 车辆进出统计-折线图
     * @param vo
     * @return
     */
    @RequestMapping("/statisticsData")
    @ResponseBody
    public ResultUtil<Map<String, Object>> statisticsData(@RequestBody DeclareCarVo vo) {
        return ResultUtil.build(declareCarService.getStatisticsData(vo),ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 车辆进出统计-列表
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getList")
    @ResponseBody
    public ResultUtil<List<DeclareCarVo>> getList(HttpServletRequest request,@RequestBody DeclareCarVo vo){
        Page<DeclareCarVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<DeclareCarVo> list = declareCarService.getList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }

}
